package com.qing.mvc.conver;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConverter implements Converter<String, Date> {

	private String dataPattern;

	public void setDataPattern(String dataPattern) {
		this.dataPattern = dataPattern;
	}

	@Override
	public Date convert(String source)  {
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat(dataPattern);
		try {
			return simpleDateFormat.parse(source);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

}
